#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

class Person
{
public:
    Person(string name, int age)
    {
        this->name = name;
        this->age = age;
    }
    string name;
    int age;
};

//存放自定义类型
void test01() {
    vector<Person> arr;
    Person p1("张三", 10);
    Person p2("李四", 20);
    Person p3("王五", 30);
    Person p4("赵六", 40);
    Person p5("孙七", 50);

    arr.push_back(p1);
    arr.push_back(p2);
    arr.push_back(p3);
    arr.push_back(p4);
    arr.push_back(p5);

    //遍历：
    for (vector<Person> :: iterator it = arr.begin(); it != arr.end(); it++) {
        cout << it -> name << "---" << it -> age << endl;
    }
}

//存放自定义类型指针
void test02(){
    vector<Person*> arr;
    Person p1("张三", 10);
    Person p2("李四", 20);
    Person p3("王五", 30);
    Person p4("赵六", 40);
    Person p5("孙七", 50);

    arr.push_back(&p1);
    arr.push_back(&p2);
    arr.push_back(&p3);
    arr.push_back(&p4);
    arr.push_back(&p5);

    //遍历：
    for (vector<Person*>::iterator it = arr.begin(); it != arr.end(); it++) {
        cout << (*it) -> name << "---" << (*it) -> age << endl;
    }
}

int main() {
    test01();
    cout << "------------------" << endl;
    test02();
    return 0;
}